/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Gui;

import java.awt.Graphics;
import java.awt.Image;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import Params.ChatMessage;
import Params.ServerSocketItem;

/**
 *
 * @author Administrator
 */
public final class frmRemoteDesktop extends javax.swing.JInternalFrame {

    Socket _sockhientai = null;
    boolean _stop = true;

    /**
     * Creates new form frmRemoteDesktop
     */
    public frmRemoteDesktop() {
        initComponents();
    }

    frmRemoteDesktop(String strPort, Socket temp) throws InterruptedException {
        initComponents();

        //initServer(strPort);
        _sockhientai = temp;
        int temp1 = (temp.getPort());
        this.title = "REMOTE DESKTOP - CLIENT " + temp1 + "";

        capturescreen();
    }

    void capturescreen() throws InterruptedException {

        for (int i = 0; i < MainSever.listConnection.size(); i++) {
            ServerSocketItem temp = (ServerSocketItem) MainSever.listConnection.elementAt(i);
            Socket _tempsock = temp.getSOCK();
            if (_tempsock.getPort() == _sockhientai.getPort()) {
                temp.getConnectionremote().bufferedWriter.println("Thong Bao Chup Hinh");
                temp.getConnectionremote().bufferedWriter.flush();
                break;
            }
        }
    }

    /**
     * // * This method is called from within the constructor to initialize the
     * form. WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jpane = new javax.swing.JPanel();

        setClosable(true);
        setMaximizable(true);
        setTitle("Spy Screen Client");
        setAutoscrolls(true);
        setPreferredSize(new java.awt.Dimension(800, 600));

        jpane.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                frmRemoteDesktop.this.mouseReleased(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                frmRemoteDesktop.this.mousePressed(evt);
            }
        });
        jpane.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseMoved(java.awt.event.MouseEvent evt) {
                frmRemoteDesktop.this.mouseMoved(evt);
            }
        });
        jpane.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                frmRemoteDesktop.this.keyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                frmRemoteDesktop.this.keyReleased(evt);
            }
        });

        javax.swing.GroupLayout jpaneLayout = new javax.swing.GroupLayout(jpane);
        jpane.setLayout(jpaneLayout);
        jpaneLayout.setHorizontalGroup(
            jpaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 800, Short.MAX_VALUE)
        );
        jpaneLayout.setVerticalGroup(
            jpaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 600, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mouseMoved
        // TODO add your handling code here:
    }//GEN-LAST:event_mouseMoved

    private void mousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_mousePressed

    private void mouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mouseReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_mouseReleased

    private void keyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_keyPressed

    private void keyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_keyReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jpane;
    // End of variables declaration//GEN-END:variables

    void onRead(ChatMessage message) {
//        ImageIcon icon = (ImageIcon) message.getImg();
//        jimage.setIcon(icon);
        Image imgn = message.getImg().getImage();
        imgn = imgn.getScaledInstance(jpane.getWidth(), jpane.getHeight(), Image.SCALE_FAST);
        Graphics g = jpane.getGraphics();
        g.drawImage(imgn, 0, 0, jpane.getWidth(), jpane.getHeight(), jpane);

        for (int i = 0; i < MainSever.listConnection.size(); i++) {
            ServerSocketItem temp = (ServerSocketItem) MainSever.listConnection.elementAt(i);
            Socket _tempsock = temp.getSOCK();
            if (_tempsock.getPort() == _sockhientai.getPort()) {

                temp.getConnectionremote().bufferedWriter.println("Thong Bao Chup Hinh");
                temp.getConnectionremote().bufferedWriter.flush();

                break;
            }

        }
    }
}
